<template>
  <div class="app-container">
   <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="Plus"
          @click="handleAdd"
          v-hasPermi="['system:molding:add']"
        >新增</el-button>
      </el-col>
   </el-row>
   <el-table v-loading="loading" :data="moldingList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键ID" align="center" prop="id" />
      <el-table-column label="产品ID" align="center" prop="pid" /> -->
      <!-- <el-table-column label="产品类型" align="center" prop="ptype" /> -->
      <el-table-column label="料号" align="center" prop="partNumber" width="150px"/>
      <el-table-column label="零件名称" align="center" prop="partName" width="150px" />
      <el-table-column label="材质" align="center" prop="material" width="250px"/>
      <el-table-column label="单位用量" align="center" prop="unitDosage" />
      <el-table-column label="材料单价" align="center" prop="unitPrice" />
      <el-table-column label="净重" align="center" prop="netWeight" />
      <el-table-column label="料头重" align="center" prop="materialHeadWeight" />
      <el-table-column label="次料" align="center" prop="inferiorMaterial" />
      <el-table-column label="废料价格" align="center" prop="wasteMaterialPrice" />
      <el-table-column label="模穴数" align="center" prop="cavitiesNumber" />
      <el-table-column label="材料损耗率" align="center" prop="materialWastageRate" />
      <el-table-column label="材料不良率" align="center" prop="materialDefectRate" />
      <el-table-column label="材料其他费用" align="center" prop="materialOtherExpenses" />
      <el-table-column label="材料管理费占比" align="center" prop="materialManagementRate" />
      <el-table-column label="材料利润占比" align="center" prop="materialProfitRate" />
      <el-table-column label="注塑其他" align="center" prop="injectionMoldingOther" />
      <el-table-column label="耗料" align="center" prop="materialConsumer" />
      <el-table-column label="料头损耗率" align="center" prop="headLossRate" />
      <el-table-column label="辅材费用" align="center" prop="auxiliaryCost" />
      <el-table-column label="材料不良费" align="center" prop="materialDefectFee" />
      <el-table-column label="材料成本" align="center" prop="materialCost" />
      <el-table-column label="材料管理费" align="center" prop="materialManagementFee" />
      <el-table-column label="材料利润" align="center" prop="materialProfit" />
      <el-table-column label="材料成本合计" align="center" prop="materialTotalCost" />
      <el-table-column label="机台型号" align="center" prop="machineModel" />
      <el-table-column label="模具类型" align="center" prop="moldType" />
      <el-table-column label="成本率" align="center" prop="costRate" />
      <el-table-column label="周期" align="center" prop="period" />
      <el-table-column label="秒/时" align="center" prop="periodUnit" />
      <el-table-column label="效率" align="center" prop="efficiency" />
      <el-table-column label="模具维修天数" align="center" prop="moldFixDays" />
      <el-table-column label="模具维修费用" align="center" prop="moldFixCost" />
      <el-table-column label="模具维修其他费用" align="center" prop="moldFixOtherCost" />
      <el-table-column label="模具工时不良率" align="center" prop="moldDefectRate" />
      <el-table-column label="模具注塑其他费用" align="center" prop="moldInjectionOtherCost" />
      <el-table-column label="模具注塑管理费占比" align="center" prop="moldInjectionManagementRate" />
      <el-table-column label="模具注塑利润占比" align="center" prop="moldInjectionProfitRate" />
      <el-table-column label="模具注塑利润占比" align="center" prop="moldFixCostPcs" />
      <el-table-column label="模具加工不良费用" align="center" prop="moldDefectCost" />
      <el-table-column label="模具注塑成本" align="center" prop="moldInjectionCost" />
      <el-table-column label="模具注塑管理费" align="center" prop="moldInjectionManagementCost" />
      <el-table-column label="模具利润" align="center" prop="moldProfit" />
      <el-table-column label="注塑成本合计" align="center" prop="moldTotalCost" />
      <el-table-column label="工站名称" align="center" prop="workstation" />
      <el-table-column label="注塑工程师人力" align="center" prop="injectionEngineerCount" />
      <el-table-column label="注塑工程师工费率" align="center" prop="injectionEngineerRate" />
      <el-table-column label="工时" align="center" prop="laborHours" />
      <el-table-column label="人工费" align="center" prop="laborCost" />
      <el-table-column label="总成本" align="center" prop="totalCost" />
      <el-table-column label="产能" align="center" prop="capacityKpcsPerDay" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width" fixed="right">
        <template #default="scope">
          <el-button link type="primary" icon="Edit" @click="handleUpdate(scope.row)" v-hasPermi="['system:molding:edit']">修改</el-button>
          <el-button link type="primary" icon="Delete" @click="handleDelete(scope.row)" v-hasPermi="['system:molding:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 添加或修改注塑件成本对话框 -->
     
    <el-dialog :title="title"  v-model="open" width="1500px" append-to-body>
      <div class = "dialog-content">
            <el-form ref="moldingRef" :model="form" :rules="rules" label-width="150px">
              <el-row :gutter="20">
               <el-col :span="12">
                 <el-form-item label="产品ID" prop="pid">
                  <el-input v-model="form.pid" placeholder="请输入产品ID" />
                </el-form-item>
              </el-col>
              <el-col :span="12">
                <el-form-item label="料号" prop="partNumber">
                  <el-input v-model="form.partNumber" placeholder="请输入料号" />
                </el-form-item>
                </el-col>
                  </el-row>

              <el-row :gutter="20">
                <el-col :span="12">
              <el-form-item label="零件名称" prop="partName">
                <el-input v-model="form.partName" placeholder="请输入零件名称" />
              </el-form-item>
               </el-col>
              <el-col :span="12">
              <el-form-item label="材质" prop="material">
                <el-input v-model="form.material" placeholder="请输入材质" />
              </el-form-item>
              </el-col>
              </el-row>

              <el-row :gutter="20">
                <el-col :span="12">
              <el-form-item label="单位用量" prop="unitDosage">
                <el-input v-model="form.unitDosage" placeholder="请输入单位用量" />
              </el-form-item>
              </el-col>
              <el-col :span="12">
              <el-form-item label="材料单价" prop="unitPrice">
                <el-input v-model="form.unitPrice" placeholder="请输入材料单价" />
              </el-form-item>
              </el-col>
            </el-row>

              <el-row :gutter="20">
                 <el-col :span="12">
              <el-form-item label="净重" prop="netWeight">
                <el-input v-model="form.netWeight" placeholder="请输入净重" />
              </el-form-item>
              </el-col>
              <el-col :span="12">
              <el-form-item label="料头重" prop="materialHeadWeight">
                <el-input v-model="form.materialHeadWeight" placeholder="请输入料头重" />
              </el-form-item>
              </el-col>
              </el-row>

              <el-row :gutter="20">
              <el-col :span="12">
              <el-form-item label="次料" prop="inferiorMaterial">
                <el-input v-model="form.inferiorMaterial" placeholder="请输入次料" />
              </el-form-item>
              </el-col>
              <el-col :span="12">
              <el-form-item label="废料价格" prop="wasteMaterialPrice">
                <el-input v-model="form.wasteMaterialPrice" placeholder="请输入废料价格" />
              </el-form-item>
               </el-col>
                </el-row>

              <el-row :gutter="20">
                <el-col :span="12">
                  <el-form-item label="模穴数" prop="cavitiesNumber">
                    <el-input v-model="form.cavitiesNumber" placeholder="请输入模穴数" />
                  </el-form-item>
              </el-col>
              <el-col :span="12">
                  <el-form-item label="材料损耗率" prop="materialWastageRate">
                    <el-input v-model="form.materialWastageRate" placeholder="请输入材料损耗率" />
                  </el-form-item>
              </el-col>
              </el-row>
              <el-row :gutter="20">
              <el-col :span="12">
              <el-form-item label="材料不良率" prop="materialDefectRate">
                <el-input v-model="form.materialDefectRate" placeholder="请输入材料不良率" />
              </el-form-item>
              </el-col>
              <el-col :span="12">
              <el-form-item label="材料其他费用" prop="materialOtherExpenses">
                <el-input v-model="form.materialOtherExpenses" placeholder="请输入材料其他费用" />
              </el-form-item>
              </el-col>
              </el-row>

              <el-row :gutter="20">
                <el-col :span="12">
              <el-form-item label="材料管理费占比" prop="materialManagementRate">
                <el-input v-model="form.materialManagementRate" placeholder="请输入材料管理费占比" />
              </el-form-item>
               </el-col>
              <el-col :span="12">
              <el-form-item label="材料利润占比" prop="materialProfitRate">
                <el-input v-model="form.materialProfitRate" placeholder="请输入材料利润占比" />
              </el-form-item>
              </el-col>
             </el-row>
              <!-- <el-row :gutter="20"> -->


              <!-- <el-form-item label="耗料" prop="materialConsumer">
                <el-input v-model="form.materialConsumer" placeholder="请输入耗料" disabled />
              </el-form-item>
              <el-form-item label="料头损耗率" prop="headLossRate">
                <el-input v-model="form.headLossRate" placeholder="请输入料头损耗率"  disabled  />
              </el-form-item>
              <el-form-item label="辅材费用" prop="auxiliaryCost">
                <el-input v-model="form.auxiliaryCost" placeholder="请输入辅材费用" disabled  />
              </el-form-item> -->
                    <!-- </el-row> -->
              <!-- <el-row :gutter="20">

            <el-form-item label="材料不良费" prop="materialDefectFee">
                <el-input v-model="form.materialDefectFee" placeholder="请输入材料不良费" disabled  />
              </el-form-item>
              <el-form-item label="材料成本" prop="materialCost">
                <el-input v-model="form.materialCost" placeholder="请输入材料成本" disabled />
              </el-form-item>
              <el-form-item label="材料管理费" prop="materialManagementFee">
                <el-input v-model="form.materialManagementFee" placeholder="请输入材料管理费" disabled />
              </el-form-item>
              <el-form-item label="材料利润" prop="materialProfit">
                <el-input v-model="form.materialProfit" placeholder="请输入材料利润" disabled />
              </el-form-item>
                    </el-row> -->
              <el-row :gutter="20">
              <!-- <el-form-item label="材料成本合计" prop="materialTotalCost">
              <el-input v-model="form.materialTotalCost" placeholder="请输入材料成本合计" disabled />
              </el-form-item> -->
              <el-col :span="12">
              <el-form-item label="注塑其他" prop="injectionMoldingOther">
                <el-input v-model="form.injectionMoldingOther"  placeholder="请输入内容" />
              </el-form-item>
                </el-col>
              <el-col :span="12">
              <el-form-item label="机台型号" prop="machineModel">
                <el-input v-model="form.machineModel" placeholder="请输入机台型号" />
              </el-form-item>
              </el-col>
                </el-row>

              <el-row :gutter="20">
              <el-col :span="12">
              <el-form-item label="成本率" prop="costRate">
                <el-input v-model="form.costRate" placeholder="请输入成本率" />
              </el-form-item>
                </el-col>
              <el-col :span="12">
              <el-form-item label="周期" prop="period">
                <el-input v-model="form.period" placeholder="请输入周期" />
              </el-form-item>
              </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="12">
              <el-form-item label="秒/时" prop="periodUnit">
                <el-input v-model="form.periodUnit" placeholder="请输入秒/时" />
              </el-form-item>
              </el-col>
              <el-col :span="12">
              <el-form-item label="效率" prop="efficiency">
                <el-input v-model="form.efficiency" placeholder="请输入效率" />
              </el-form-item>
              </el-col>
                </el-row>
            <el-row :gutter="20">
              <el-col :span="12">
              <el-form-item label="模具维修天数" prop="moldFixDays">
                <el-input v-model="form.moldFixDays" placeholder="请输入模具维修天数" />
              </el-form-item>
              </el-col>
              <el-col :span="12">
              <el-form-item label="模具维修费用" prop="moldFixCost">
                <el-input v-model="form.moldFixCost" placeholder="请输入模具维修费用" />
              </el-form-item>
              </el-col>
              </el-row>
              <el-row :gutter="20">
                <el-col :span="12">
              <el-form-item label="模具维修其他费用" prop="moldFixOtherCost">
                <el-input v-model="form.moldFixOtherCost" placeholder="请输入模具维修其他费用" />
              </el-form-item>
              </el-col>
              <el-col :span="12">
              <el-form-item label="模具工时不良率" prop="moldDefectRate">
                <el-input v-model="form.moldDefectRate" placeholder="请输入模具工时不良率" />
              </el-form-item>
              </el-col>
                </el-row>

              <el-row :gutter="20">
              <el-col :span="12">
              <el-form-item label="模具注塑其他费用" prop="moldInjectionOtherCost">
                <el-input v-model="form.moldInjectionOtherCost" placeholder="请输入模具注塑其他费用" />
              </el-form-item>
               </el-col>
              <el-col :span="12">
              <el-form-item label="模具注塑管理费占比" prop="moldInjectionManagementRate">
                <el-input v-model="form.moldInjectionManagementRate" placeholder="请输入模具注塑管理费占比" />
              </el-form-item>
               </el-col>
            </el-row>
              <!-- <el-row :gutter="20">
              <el-form-item label="模具注塑利润占比" prop="moldInjectionProfitRate">
                <el-input v-model="form.moldInjectionProfitRate" placeholder="请输入模具注塑利润占比" />
              </el-form-item> -->
              <!-- <el-form-item label="模具维修费用/pcs" prop="moldFixCostPcs">
                <el-input v-model="form.moldFixCostPcs" placeholder="请输入模具维修费用/pcs" disabled />
              </el-form-item>
              <el-form-item label="模具加工不良费用" prop="moldDefectCost">
                <el-input v-model="form.moldDefectCost" placeholder="请输入模具加工不良费用" disabled />
              </el-form-item>
              <el-form-item label="模具注塑成本" prop="moldInjectionCost">
                <el-input v-model="form.moldInjectionCost" placeholder="请输入模具注塑成本" disabled />
              </el-form-item> -->
                    <!-- </el-row> -->
              <!-- <el-row :gutter="20"> -->

            <!-- <el-form-item label="模具注塑管理费" prop="moldInjectionManagementCost">
                <el-input v-model="form.moldInjectionManagementCost" placeholder="请输入模具注塑管理费" disabled/>
              </el-form-item> -->
              <!-- <el-form-item label="模具利润" prop="moldProfit">
                <el-input v-model="form.moldProfit" placeholder="请输入模具利润" disabled/>
              </el-form-item>
              <el-form-item label="注塑成本合计" prop="moldTotalCost">
                <el-input v-model="form.moldTotalCost" placeholder="请输入注塑成本合计" disabled/>
              </el-form-item> -->
              <!-- <el-form-item label="工站名称" prop="workstation">
                <el-input v-model="form.workstation" placeholder="请输入工站名称" />
              </el-form-item>
                    </el-row> -->
              <el-row :gutter="20">
                <el-col :span="12">
              <el-form-item label="模具注塑利润占比" prop="moldInjectionProfitRate">
                <el-input v-model="form.moldInjectionProfitRate" placeholder="请输入模具注塑利润占比" />
              </el-form-item>
                  </el-col>
              <el-col :span="12">
              <el-form-item label="工站名称" prop="workstation">
                <el-input v-model="form.workstation" placeholder="请输入工站名称" />
              </el-form-item>
              </el-col>
                </el-row>

              <el-row :gutter="20">
                <el-col :span="12">
              <el-form-item label="注塑工程师人力" prop="injectionEngineerCount">
                <el-input v-model="form.injectionEngineerCount" placeholder="请输入注塑工程师人力" />
              </el-form-item>
                  </el-col>
              <el-col :span="12">
              <el-form-item label="注塑工程师工费率" prop="injectionEngineerRate">
                <el-input v-model="form.injectionEngineerRate" placeholder="请输入注塑工程师工费率" />
                </el-form-item>
              </el-col>
               </el-row>
              <el-row :gutter="20">
              <el-col :span="12">
              <el-form-item label="工时" prop="laborHours">
                <el-input v-model="form.laborHours" placeholder="请输入工时" />
              </el-form-item>
              </el-col>
              <el-col :span="12">
              <el-form-item label="人工费" prop="laborCost">
                <el-input v-model="form.laborCost" placeholder="请输入人工费" />
              </el-form-item>
                </el-col>
                </el-row>

              <el-row :gutter="20">
              <el-col :span="12">
              <el-form-item label="总成本" prop="totalCost">
                <el-input v-model="form.totalCost" placeholder="请输入总成本" />
              </el-form-item>
                  </el-col>
              <el-col :span="12">
              <el-form-item label="产能" prop="capacityKpcsPerDay">
                <el-input v-model="form.capacityKpcsPerDay" placeholder="请输入产能" />
              </el-form-item>
                </el-col>
              </el-row>
            </el-form>
      <hr color="#f3f3f3" margin-top="20px"/>
       <div class="calculate">
          <el-row :gutter="20">
            <el-col :span="4">
            耗料: {{ consumerMaterial }}
            </el-col>
            <el-col :span="20">
              <!-- 计算公式：{如果模穴数不空} ({净重}+{料头重}/{模穴数})*(1+{材料损耗率}+{材料不良率})*(1-{次料})  如果模穴数为空 结果为“ ”  -->
              计算公式："(净重{{ data.form.netWeight }}+料头重{{ data.form.materialHeadWeight }}/模穴数{{ data.form.cavitiesNumber }})*(1+材料损耗率{{ data.form.materialDefectRate }}+材料不良率{{ data.form.materialDefectRate }})*(1-次料{{ data.form.inferiorMaterial }})"
            </el-col>
          </el-row>

          <el-row :gutter="20">
            <el-col :span="4">
            料头损耗率:{{ headLossRate }}
            </el-col>
            <el-col :span="20">
              计算公式：如何单位用量为空 结果为空 如果不为空 结果为"1%"
            </el-col>
            </el-row>

          <el-row :gutter="20">
            <el-col :span="4">
            辅材费用:{{ auxiliaryCost }}
            </el-col>
            <el-col :span="20">
              计算公式：=IF(E3="","",0) 如果单位用量为空 结果为空否则为0
            </el-col>
          </el-row>

          
          <el-row :gutter="20">
            <el-col :span="4">
            材料不良费: {{ materialDefectFee }}
            </el-col>
            <el-col :span="20">
              <!-- 计算公式：   return (data.form.unitPrice/1000*(data.form.netWeight+data.form.materialHeadWeight/data.form.cavitiesNumber)*(1-data.form.inferiorMaterial)
            -data.form.wasteMaterialPrice/1000*(data.form.netWeight+data.form.materialHeadWeight/data.form.cavitiesNumber)*(1-data.form.headLossRate)*(1-data.form.inferiorMaterial)+data.form.auxiliaryCost)*data.form.materialDefectRate
            -->
            计算公式："如果模穴数不为空(材料单价{{data.form.unitPrice}}/1000*（净重{{data.form.netWeight}}+料头重 {{data.form.materialHeadWeight}} /模穴数{{ data.form.cavitiesNumber }}*(1-次料{{ data.form.inferiorMaterial }}）-废料单价{{ data.form.wasteMaterialPrice }}/1000*(净重{{ data.form.netWeight }}
              +料头重{{ data.form.materialHeadWeight }} / 模穴数 {{ data.form.cavitiesNumber }})*(1-料头损耗率{{ data.form.headLossRate }})*(1-次料{{ data.form.inferiorMaterial }})+辅材费用{{ auxiliaryCost }})*材料不良率{{ data.form.materialDefectRate }} 如果模穴数为空 结果为空"
            <!-- 计算公式： "如果模穴数不为空 (材料单价/1000*(净重+料头重/模穴数)*(1-次料)-废料单价/1000*(净重+料头重/模穴数)*(1-料头损耗率)*(1-次料)+辅材费用)*材料不良率 如果模穴数为空 结果为空" -->

            </el-col>
          </el-row>

          <el-row :gutter="20">
            <el-col :span="4">
            材料成本: {{ materialCost }}
            </el-col>
            <el-col :span="20">
              计算公式：如果模穴数不为空 (材料单价{{data.form.unitPrice}}/1000*(净重{{data.form.netWeight}}+料头重{{data.form.materialHeadWeight}}/模穴数{{ data.form.cavitiesNumber }})*(1+材料损耗率{{ data.form.materialWastageRate }})*(1-次料{{ data.form.inferiorMaterial }})-废料单价{{data.form.wasteMaterialPrice}}/1000*料头重{{data.form.materialHeadWeight}}/模穴数{{data.form.cavitiesNumber}}*(1-料头损耗率{{ data.form.headLossRate }})*(1-次料{{ data.form.inferiorMaterial }})+辅材费用{{ data.form.auxiliaryCost }})+材料不良费{{data.form.materialDefectFee}}+注塑其他{{data.form.moldInjectionManagementRate }} 如果模穴数为空 结果为" "
              <!-- //        return (data.form.unitPrice/1000*(data.form.netWeight+data.form.materialHeadWeight/data.form.cavitiesNumber)*(1+data.form.materialWastageRate)*(1-data.form.inferiorMaterial)
    //        -data.form.wasteMaterialPrice/1000*data.form.materialHeadWeight/data.form.cavitiesNumber*(1-data.form.headLossRate)*(1-data.form.inferiorMaterial)+data.form.auxiliaryCost)+data.form.materialDefectFee+data.form.moldInjectionManagementRate -->
            
            </el-col>
            </el-row>
                <el-row :gutter="20">
            <el-col :span="4">
            材料管理费: {{ materialManagementFee }}
            </el-col>
            <el-col :span="20">
              计算公式：如果材料成本不为空  材料成本*材料管理费占比   如果材料成本为空 结果为" "
            </el-col> 
            </el-row>
                <el-row :gutter="20">
            <el-col :span="4">
            材料利润: {{ materialProfit }}
            </el-col>
            <el-col :span="20">
              计算公式：  如果材料成本不为空  (材料成本+材料管理费)*材料利润占比   如果材料成本为空 结果为" "     
            </el-col>
            </el-row>

            <el-row :gutter="20">
            <el-col :span="4">
            材料成本合计: {{ materialTotalCost }}
            </el-col>
            <el-col :span="20">
              计算公式：如果材料成本不为空  (材料成本+材料管理费+材料利润)*单位用量   如果材料成本为空 结果为" "    
            </el-col>
            </el-row>
            <!--模具相关计算-->


            <!-- 模具维修费用/pcs	模具加工不良费用	模具注塑成本	-->
            <el-row :gutter="20">
            <el-col :span="4">
            模具维修费用/pcs: {{ moldFixCostPcs }}
            </el-col>
            <el-col :span="20">
              计算公式：   模具维修费用/(模具维修天数*22*3600*模穴数/周期*效率) 
            </el-col>
            </el-row>

            <el-row :gutter="20">
            <el-col :span="4">
            模具加工不良费用: {{ moldDefectCost }}
            </el-col>
            <el-col :span="20">
              计算公式：(成本率/(模穴数/周期*秒/时*效率)+模具维修费用/pcs+模具维修其他费用)*模具工时不良率 =(AB3/(K3/AC3*AD3*AE3)+AM3+AH3)*AI3
            </el-col>
            </el-row>


            <el-row :gutter="20">
            <el-col :span="4">
            模具注塑成本: {{ moldInjectionCost }}
            </el-col>
            <el-col :span="20">
              计算公式：成本率/(模穴数/周期*秒/时*效率)+模具维修费用/pcs+模具加工不良费用+模具维修其他费用 =AB2/(K2/AC2*AD2*AE2)+AM2+AN2+AH2
            </el-col>
            </el-row>
            <!-- 模具注塑管理费	模具利润	注塑成本合计 -->

            <el-row :gutter="20">
            <el-col :span="4">
            模具注塑管理费: {{ moldInjectionManagementCost }}
            </el-col>
            <el-col :span="20">
              计算公式：模具注塑成本*模具注塑管理费占比    =AO2*AK2 
            </el-col>
            </el-row>

            <el-row :gutter="20">
            <el-col :span="4">
            模具利润: {{ moldProfit }}
            </el-col>
            <el-col :span="20">
              计算公式： (模具注塑成本+模具注塑管理费)*材料管理费          =IF(AO3="","",(AO3+AP3)*W3)  
            </el-col>
            </el-row>

            <el-row :gutter="20">
            <el-col :span="4">
            注塑成本合计: {{ moldTotalCost }}
            </el-col>
            <el-col :span="20">
              计算公式：(模具注塑成本+模具注塑管理费+模具利润)*单位用量  =(AO2+AP2+AQ2)*E2 
            </el-col>
            </el-row>
          <!-- 工时	人工费	总成本	产能（Kpcs/D） -->
          <el-row :gutter="20">
            <el-col :span="4">
            工时: {{ laborHours }}
            </el-col>
            <el-col :span="20">
              计算公式： 周期/模穴数 =AC2/K2 
            </el-col>
            </el-row>

            <el-row :gutter="20">
            <el-col :span="4">
            人工费: {{ laborCost }}
            </el-col>
            <el-col :span="20">
              计算公式：注塑工程师人力{{data.form.injectionEngineerCount}}*注塑工程师工费率{{data.form.injectionEngineerRate}}/3600*工时{{laborHours}}*单位用量{{ data.form.unitDosage }}    =AT3*AU3/3600*AV3*E3
          </el-col>
            </el-row>
            <el-row :gutter="20">
            <el-col :span="4">
            总成本: {{ totalCost }}
            </el-col>
            <el-col :span="20">
              计算公式：材料成本合计+注塑成本合计+人工费 =Y2+AR2+AW2
            </el-col>
            </el-row>

            <el-row :gutter="20">
            <el-col :span="4">
            产能（Kpcs/D）: {{ capacityKpcsPerDay }}
            </el-col>
            <el-col :span="20">
              计算公式：22*秒/时{{data.form.periodUnit}}*模穴数{{data.form.cavitiesNumber}}/周期{{data.form.period}}*效率{{data.form.efficiency}}/1000*(1-材料不良率{{ data.form.materialDefectRate }})   =22*AD3*K3/AC3*AE3/1000*(1-M3)
            </el-col>
            </el-row>
    </div>

    <div style="text-align: right;">
      <el-button type="primary" @click="submitForm">确 定</el-button>
      <el-button @click="cancel">取 消</el-button>
    </div>
  </div>
   </el-dialog>


  </div>


</template>

<script setup name="Molding">
import { listMolding, getMolding, delMolding, addMolding, updateMolding } from "@/api/system/molding"
const { proxy } = getCurrentInstance()
const moldingList = ref([])
const open = ref(false)
const loading = ref(true)
const showSearch = ref(true)
const ids = ref([])
const single = ref(true)
const multiple = ref(true)
const total = ref(0)
const title = ref("")

const data = reactive({
  form: {},
  queryParams: {
    pageNum: 1,
    pageSize: 10,
    pid: null,
  },
  rules: {
    pid: [
      { required: true, message: "产品ID不能为空", trigger: "blur" }
    ],
    ptype: [
      { required: true, message: "产品类型不能为空", trigger: "change" }
    ],
    unitDosage: [
      { required: true, message: "单位用量不能为空", trigger: "blur" }
    ],
    unitPrice: [
      { required: true, message: "材料单价不能为空", trigger: "blur" }
    ],
  }
})

//耗料 计算公式：如果模穴数不空 (净重+料头重/模穴数)*(1+材料损耗率+材料不良率)*(1-次料)  如果模穴数为空 结果为“ ”
const consumerMaterial = computed(() => {

   if(data.form.cavitiesNumber == ""){
      return ""
   }
    const form = data.form;
    const netWeight = Number(form.netWeight ?? 0);
    const headWeight = Number(form.materialHeadWeight ?? 0);
    const cavities = Number(form.cavitiesNumber ?? 1) || 1; // 防止0
    const wastage = Number(form.materialWastageRate ?? 0);
    const defect = Number(form.materialDefectRate ?? 0);
    const inferior = Number(form.inferiorMaterial ?? 0);
  //  return (data.form.netWeight+data.form.materialHeadWeight/data.form.cavitiesNumber)*(1+data.form.materialWastageRate+data.form.materialDefectRate)*(1-data.form.inferiorMaterial)
  return Number(
    ((netWeight + headWeight / cavities) * 
     (1 + wastage + defect) * 
     (1 - inferior)).toFixed(4)
  );
})
watchEffect(() => {
  data.form.consumerMaterial = consumerMaterial.value
});

//料头损耗率 计算公式 如何单位用量为空 结果为空 如果不为空 结果为"%"
const headLossRate = computed(
   ()=>data.form.unitDosage=="" || data.form.unitDosage==null?"":"1%"
)

//辅材费用 计算公式：=IF(E3="","",0) 如果单位用量为空 结果为空否则为0
const auxiliaryCost = computed(() => {
     return data.form.unitDosage=="" || data.form.unitDosage==null?"":0
})

watchEffect(() => {
  data.form.headLossRate = headLossRate.value
  data.form.auxiliaryCost = auxiliaryCost.value
});


//材料不良费 计算公式： 如果模穴数不为空 (材料单价/1000*(净重+料头重/模穴数)*(1-次料)-废料单价/1000*(净重+料头重/模穴数)*(1-料头损耗率)*(1-次料)+辅材费用)*材料不良率 如果模穴数为空 结果为" "
// const materialDefectFee = computed(
//   () => {
//     if(data.form.cavitiesNumber == ""){
//         return ""
//     }
//        return (data.form.unitPrice/1000*(data.form.netWeight+data.form.materialHeadWeight/data.form.cavitiesNumber)*(1-data.form.headLossRate)
//        -data.form.wasteMaterialPrice/1000*(data.form.netWeight+data.form.materialHeadWeight/data.form.cavitiesNumber)*(1-data.form.headLossRate)*(1-data.form.inferiorMaterial)+data.form.auxiliaryCost)*data.form.materialDefectRate
//     }
// )

const materialDefectFee = computed(() => {
    if(data.form.cavitiesNumber == ""){
        return ""
    }
  const form = data.form || {};
  
  // 1. 安全转换所有输入值（提取公共变量）
  const unitPrice = Number(form.unitPrice ?? 0) / 1000;
  const wastePrice = Number(form.wasteMaterialPrice ?? 0) / 1000;
  const auxiliaryCost = Number(form.auxiliaryCost ?? 0);
  
  const netWeight = Number(form.netWeight ?? 0);
  const headWeight = Number(form.materialHeadWeight ?? 0);
  const cavities = Number(form.cavitiesNumber ?? 1) || 1; // 防除零
  const headLossRate = Number(form.headLossRate ?? 0);
  const inferiorRate = Number(form.inferiorMaterial ?? 0);
  const defectRate = Number(form.materialDefectRate ?? 0);

  // 2. 提取公共子表达式（关键优化点）
  const baseWeight = netWeight + headWeight / cavities;
  const afterHeadLoss = baseWeight * (1 - headLossRate);
  
  // 3. 分步计算（公式对应原式）
  const mainCost = unitPrice * afterHeadLoss;
  const wasteDeduction = wastePrice * afterHeadLoss * (1 - inferiorRate);
  const subTotal = mainCost - wasteDeduction + auxiliaryCost;
  
  // 4. 最终结果
  const result = subTotal * defectRate;
  
  // 5. 处理精度，保留4位小数
  return Number(result.toFixed(4));
});

watchEffect(() => {
data.form.materialDefectFee = materialDefectFee.value
});
// 材料成本 计算公式：  计算公式：如果模穴数不为空 (材料单价/1000*(净重+料头重/模穴数)*(1+材料损耗率)*(1-次料)-废料单价/1000*料头重/模穴数*(1-料头损耗率)*(1-次料)+辅材费用)+材料不良费+注塑其他 如果模穴数为空 结果为" ""
// const materialTotalCost = computed(
//   () => {
//     if(data.form.cavitiesNumber == ""){
//         return ""
//     }
//        return (data.form.unitPrice/1000*(data.form.netWeight+data.form.materialHeadWeight/data.form.cavitiesNumber)*(1+data.form.materialWastageRate)*(1-data.form.inferiorMaterial)
//        -data.form.wasteMaterialPrice/1000*data.form.materialHeadWeight/data.form.cavitiesNumber*(1-data.form.headLossRate)*(1-data.form.inferiorMaterial)+data.form.auxiliaryCost)+data.form.materialDefectFee+data.form.moldInjectionManagementRate
//   }
// )


const materialCost = computed(() => {
   if(data.form.cavitiesNumber == ""){
        return ""
    }
  const form = data.form || {};
  
  // 第一层：安全转换所有原始数据（提取公共系数）
  const unitPrice = Number(form.unitPrice ?? 0) / 1000;
  const wastePrice = Number(form.wasteMaterialPrice ?? 0) / 1000;
  const auxiliaryCost = Number(form.auxiliaryCost ?? 0);
  const defectFee = Number(form.materialDefectFee ?? 0);
  const manageRate = Number(form.moldInjectionManagementRate ?? 0);
  
  const netWeight = Number(form.netWeight ?? 0);
  const headWeight = Number(form.materialHeadWeight ?? 0);
  const cavities = Number(form.cavitiesNumber ?? 1) || 1; // 防除零
  
  const wastageRate = Number(form.materialWastageRate ?? 0);
  const inferiorRate = Number(form.inferiorMaterial ?? 0);
  const headLossRate = Number(form.headLossRate ?? 0);

  // 第二层：提取高频子表达式（核心优化）
  const headWeightPerCavity = headWeight / cavities;  // 公共：料头重量分摊
  const qualityFactor = 1 - inferiorRate;             // 公共：劣质材料系数
  const headLossFactor = 1 - headLossRate;            // 公共：料损系数

  // 第三层：计算主要组成部分
  const baseWeight = netWeight + headWeightPerCavity;   // 基础重量
  
  // 主材料成本部分
  const mainPart = unitPrice * baseWeight * (1 + wastageRate) * qualityFactor;
  
  // 废料抵扣部分
  const wastePart = wastePrice * headWeightPerCavity * headLossFactor * qualityFactor;
  
  // 第四层：汇总计算
  const subTotal = mainPart - wastePart + auxiliaryCost; // 前段合计
  const finalResult = subTotal + defectFee + manageRate; // 最终结果

  // 第五层：精度处理
  return Number(finalResult.toFixed(4));
});
watchEffect(() => {
   data.form.materialCost = materialCost.value
});


//材料管理费 计算公式：如果材料成本不为空  材料成本*材料管理费占比   如果材料成本为空 结果为" "
const materialManagementFee = computed(
  () => {
    if(data.form.materialCost == ""){
        return ""
    }
  const form = data.form || {};
  const materialCost = Number(form.materialCost ?? 0);
  const materialManagementRate = Number(form.materialManagementRate ?? 0);
   return materialCost.value*materialManagementRate
  }
)
watchEffect(() => {
   data.form.materialManagementFee = materialManagementFee.value
});

//材料利润   计算公式：  如果材料成本不为空  (材料成本+材料管理费)*材料利润占比   如果材料成本为空 结果为" "     
const materialProfit = computed(
  () => {
    if(data.form.materialCost == ""){
        return ""
    }
  const form = data.form || {};
  const materialProfitRate = Number(form.materialProfitRate ?? 0);
   return (materialCost.value??0+materialManagementFee.value??0)*form.materialManagementRate
  }
)
watchEffect(() => {
  data.form.materialProfit = materialProfit.value;
});
//材料成本合计 材料成本+材料管理费+材料利润

const materialTotalcost = computed(() => {
   return materialCost.value + materialManagementFee.value + materialProfit.value
  })
watchEffect(() => {
  data.form.materialTotalcost = materialTotalcost.value;
});


//模具维修费用pcs     计算公式：   模具维修费用/(模具维修天数*22*3600*模穴数/周期*效率) 
// const moldFixCostPcs = computed(
//   () => {
//       return data.form.moldFixCost/(data.form.moldFixDays*22*3600*data.form.cavitiesNumber/data.form.period*data.form.efficiency)
//   }
// )
const moldFixCostPcs = computed(() => {
  const form = data.form || {};
  
  // 1. 安全提取并转换所有变量
  const moldFixCost = Number(form.moldFixCost ?? 0);
  const moldFixDays = Number(form.moldFixDays ?? 0);
  
  const cavitiesNumber = Number(form.cavitiesNumber ?? 1);
  const period = Number(form.period ?? 1);        // 生产周期（秒）
  const efficiency = Number(form.efficiency ?? 1); // 效率系数
  
  // 2. 除零保护（关键！）
  if (cavitiesNumber <= 0 || period <= 0 || efficiency <= 0) {
    console.warn('计算参数不能为零或负数', { cavitiesNumber, period, efficiency });
    return 0; // 或返回 null/NaN 表示无效
  }
  
  // 3. 分步计算分母（明确运算顺序）
  const dailySeconds = 22 * 3600;                // 每天工作秒数（22小时）
  const totalSeconds = moldFixDays * dailySeconds; // 总可用时间
  const cavitiesPerPeriod = cavitiesNumber / period; // 每秒产能
  const effectiveCapacity = cavitiesPerPeriod * efficiency; // 有效产能
  
  const denominator = totalSeconds * effectiveCapacity;
  
  // 4. 最终计算
  if (denominator === 0) return 0;
  
  const result = moldFixCost / denominator;
  
  // 5. 精度处理（成本通常保留6位小数）
  return Number(result.toFixed(6));
});
watchEffect(() => {
  data.form.moldFixCostPcs = moldFixCostPcs.value;
});


//模具加工不良费用  (成本率/(模穴数/周期*秒/时*效率)+模具维修费用/pcs+模具维修其他费用)*模具工时不良率 =(AB3/(K3/AC3*AD3*AE3)+AM3+AH3)*AI3
// const moldDefectCost = computed(
//   () => {
//       return (data.form.costRate/(data.form.cavitiesNumber/data.form.period*data.form.periodUnit*data.form.efficiency)+data.form.moldFixCostPcs+data.form.moldFixOtherCost)*data.form.moldDefectRate
//   }
// )


const moldDefectCost = computed(() => {
  const form = data.form || {};
  
  // 1. 安全提取并转换所有变量
  const costRate = Number(form.costRate ?? 0);
  const cavitiesNumber = Number(form.cavitiesNumber ?? 1);
  const period = Number(form.period ?? 1);
  const periodUnit = Number(form.periodUnit ?? 1);
  const efficiency = Number(form.efficiency ?? 1);
  const moldFixCostPcs = Number(form.moldFixCostPcs ?? 0);
  const moldFixOtherCost = Number(form.moldFixOtherCost ?? 0);
  const moldDefectRate = Number(form.moldDefectRate ?? 0);

  // 2. 严格除零保护（所有乘积分母因子必须>0）
  if (cavitiesNumber <= 0) {
    console.warn('模穴数必须大于0');
    return 0;
  }
  if (period <= 0) {
    console.warn('周期时间必须大于0');
    return 0;
  }
  if (periodUnit <= 0) {
    console.warn('周期单位必须大于0');
    return 0;
  }
  if (efficiency <= 0) {
    console.warn('效率必须大于0');
    return 0;
  }

  // 3. 分步计算（提取公共表达式）
  // 单位时间产能 = (模穴数 / 单件周期) × 周期单位 × 效率
  const capacityPerUnit = (cavitiesNumber / period) * periodUnit * efficiency;
  
  // 除数不能为零
  if (capacityPerUnit === 0) {
    console.warn('单位时间产能计算为零');
    return 0;
  }

  // 4. 计算基础成本（costRate ÷ 产能 + 单件成本 + 其他成本）
  const baseCost = (costRate / capacityPerUnit) + moldFixCostPcs + moldFixOtherCost;
  
  // 5. 应用缺陷率调整
  const result = baseCost * moldDefectRate;

  // 6. 精度处理（成本保留4-6位小数）
  return Number(result.toFixed(4));
});


//模具注塑成本      计算公式：成本率/(模穴数/周期*秒/时*效率)+模具维修费用/pcs+模具加工不良费用+模具维修其他费用 =AB2/(K2/AC2*AD2*AE2)+AM2+AN2+AH2
// const moldInjectionCost = computed(
//   () => {
//       return data.form.costRate/(data.form.cavitiesNumber/data.form.period*data.form.periodUnit*data.form.efficiency)+data.form.moldFixCostPcs+data.form.efficiency+data.form.moldFixOtherCost
//   }
// )
watchEffect(() => {
  data.form.moldDefectCost = moldDefectCost.value;
});


const moldInjectionCost = computed(() => {
  const form = data.form || {};
  
  // 1. 安全提取并转换所有变量（使用空值合并运算符）
  const costRate = Number(form.costRate ?? 0);
  const cavitiesNumber = Number(form.cavitiesNumber ?? 1);
  const period = Number(form.period ?? 1);
  const periodUnit = Number(form.periodUnit ?? 1);
  const efficiency = Number(form.efficiency ?? 1);
  const moldFixCostPcs = Number(form.moldFixCostPcs ?? 0);
  const moldFixOtherCost = Number(form.moldFixOtherCost ?? 0);

  // 2. 严格除零保护（所有乘积因子必须>0）
  if (cavitiesNumber <= 0) {
    console.warn('模穴数必须大于0');
    return 0;
  }
  if (period <= 0) {
    console.warn('周期时间必须大于0');
    return 0;
  }
  if (periodUnit <= 0) {
    console.warn('周期单位必须大于0');
    return 0;
  }
  if (efficiency <= 0) {
    console.warn('效率必须大于0');
    return 0;
  }

  // 3. 提取公共表达式：计算单位时间产能
  // 单位产能 = (模穴数 / 单件周期) × 周期单位 × 效率
  const capacityPerUnit = (cavitiesNumber / period) * periodUnit * efficiency;
  
  if (capacityPerUnit === 0) {
    console.warn('单位产能计算结果为零');
    return 0;
  }

  // 4. 分步计算（提高可读性）
  const costRatePerPcs = costRate / capacityPerUnit;  // 费率分摊
  const additionalCost = moldFixCostPcs + efficiency + moldFixOtherCost; // 附加成本
  
  // 5. 汇总结果
  const result = costRatePerPcs + additionalCost;

  // 6. 精度处理（成本保留4位小数）
  return Number(result.toFixed(4));
});

watchEffect(() => {
  data.form.moldInjectionCost = moldInjectionCost.value;
});

//模具注塑管理费    计算公式：模具注塑成本*模具注塑管理费占比
// const moldInjectionManagementCost = computed(
//   () => {
//       return data.form.moldInjectionCost*data.form.moldInjectionManagementCostRate
//   }
// )

const moldInjectionManagementCost = computed(() => {
  const form = data.form || {};
  
  // 1. 安全提取并转换
  const moldInjectionCost = Number(form.moldInjectionCost ?? 0);
  const managementRate = Number(form.moldInjectionManagementCostRate ?? 0);

  // 2. 计算（无需除零检查，乘法安全）
  const result = moldInjectionCost * managementRate;

  // 3. 精度处理（管理费率成本保留4位小数）
  return Number(result.toFixed(4));
});
watchEffect(() => {
  data.form.moldInjectionManagementCost = moldInjectionManagementCost.value;
});

//模具利润          计算公式： (模具注塑成本+模具注塑管理费)*材料管理费=(AO2+AP2)*AL2
// const moldProfit = computed(
//   () => {
//       return (data.form.moldInjectionCost+data.form.moldInjectionManagementCost)*data.form.moldInjectionProfitRate
//   }
// )



const moldProfit = computed(() => {
  const form = data.form || {};
  
  // 1. 安全提取并转换（空值合并运算符）
  const moldInjectionCost = Number(form.moldInjectionCost ?? 0);
  const managementCost = Number(form.moldInjectionManagementCost ?? 0);
  const profitRate = Number(form.moldInjectionProfitRate ?? 0);

  // 2. 计算总成本和利润
  const totalCost = moldInjectionCost + managementCost;
  const result = totalCost * profitRate;

  // 3. 精度处理（利润保留4位小数）
  return Number(result.toFixed(4));
});

watchEffect(() => {
  data.form.moldProfit = moldProfit.value;
});


//注塑成本合计      计算公式：(模具注塑成本+模具注塑管理费+模具利润)*单位用量  =(AO2+AP2+AQ2)*E2 
// const moldTotalCost = computed(
//   () => {
//       return (data.form.moldInjectionCost+data.form.moldInjectionManagementCost+data.form.moldProfit)*data.form.unitDosage
//   }
// )



const moldTotalCost = computed(() => {
  const form = data.form || {};
  
  // 1. 安全提取并转换
  const moldInjectionCost = Number(form.moldInjectionCost ?? 0);
  const managementCost = Number(form.moldInjectionManagementCost ?? 0);
  const moldProfit = Number(form.moldProfit ?? 0);
  const unitDosage = Number(form.unitDosage ?? 0);

  // 2. 计算总成本
  const totalCost = moldInjectionCost + managementCost + moldProfit;
  
  // 3. 最终成本
  const result = totalCost * unitDosage;

  // 4. 精度处理（保留4位小数）
  return Number(result.toFixed(4));
});
watchEffect(() => {
  data.form.moldTotalCost = moldTotalCost.value;
});

//工时:   计算公式： 周期/模穴数 
// const laborHours = computed(
//   () => {
//       return data.form.period/data.form.cavitiesNumber
//   }
// )

const laborHours = computed(() => {
  const form = data.form || {};
  
  // 1. 安全提取并转换
  const period = Number(form.period ?? 0);
  const cavitiesNumber = Number(form.cavitiesNumber ?? 1);

  // 2. 严格除零保护
  if (cavitiesNumber <= 0) {
    console.warn('模穴数必须大于0');
    return 0; // 或返回 Infinity / NaN 根据业务需求
  }

  // 3. 计算结果
  const result = period / cavitiesNumber;

  // 4. 精度处理（根据业务场景选择）
  return Number(result.toFixed(4)); // 保留4位小数
});



//人工费: 计算公式：注塑工程师人力*注塑工程师工费率/3600*工时*单位用量
// const laborCost = computed(
//   () => {
//       return data.form.injectionEngineerCount*data.form.injectionEngineerRate/3600*data.form.laborHours*data.form.unitDosage
//   }
// )

watchEffect(() => {
  data.form.laborHours = laborHours.value;
});

const laborCost = computed(() => {
  const form = data.form || {};
  // 1. 安全提取并转换所有变量
  const engineerCount = Number(form.injectionEngineerCount ?? 0);
  const engineerRate = Number(form.injectionEngineerRate ?? 0);
  // const laborHours = Number(form.laborHours ?? 0);
  const unitDosage = Number(form.unitDosage ?? 0);
  const costPerSecond = engineerCount * engineerRate ;
   return Number((costPerSecond/costPerSecond * laborHours.value * unitDosage).toFixed(4));
});


watchEffect(() => {
   data.form.laborCost = laborCost.value;
});
//总成本:  计算公式：材料成本合计+注塑成本合计+人工费

// const totalCost = computed(
//   () => {
//       return data.form.materialTotalCost+data.form.moldingCost+data.form.laborCost
//   }
// )
// import { computed } from 'vue';

const totalCost = computed(() => {
  const form = data.form || {};
  
  // 1. 安全提取并转换所有变量
  const materialCost = Number(form.materialTotalCost ?? 0);
  const moldingCost = Number(form.moldingCost ?? 0);
  const laborCost = Number(form.laborCost ?? 0);

  // 2. 直接相加（纯加法无需除零检查）
  const result = materialCost + moldingCost + laborCost;

  // 3. 精度处理（总成本保留2位小数）
  return Number(result.toFixed(4));
});
watchEffect(() => {
    data.form.totalCost = totalCost.value;
});
//产能（Kpcs/D）22*秒/时*模穴数/周期*效率/1000*(1-材料不良率) 

// const capacityKpcsPerDay = computed(
//   () => {
//       return 22*data.form.periodUnit*data.form.cavitiesNumber/data.form.period*data.form.efficiency/(1000*(1-data.form.materialDefectRate))
//   }
// )

const capacityKpcsPerDay = computed(() => {
  const form = data.form || {};
  
  // 1. 安全提取并转换
  const periodUnit = Number(form.periodUnit ?? 1);
  const cavitiesNumber = Number(form.cavitiesNumber ?? 1);
  const period = Number(form.period ?? 1);
  const efficiency = Number(form.efficiency ?? 1);
  const materialDefectRate = Number(form.materialDefectRate ?? 0);

  // 2. 严格除零保护
  if (period <= 0) {
    console.warn('周期时间必须大于0');
    return 0;
  }
  
  // 3. 计算良品率
  const goodRate = 1 - materialDefectRate;
  if (goodRate <= 0) {
    console.warn('良品率必须大于0');
    return 0;
  }
 const dailyWorkSeconds = 22 ; 
 const result = dailyWorkSeconds*periodUnit * cavitiesNumber / period * efficiency / 1000 * goodRate;
   // 4. 精度处理
  return Number(result.toFixed(4));
});

watchEffect(() => {
    data.form.capacityKpcsPerDay = capacityKpcsPerDay.value;
});


const { queryParams, form, rules } = toRefs(data)

/** 查询注塑件成本列表 */
function getList() {
  loading.value = true
  listMolding(queryParams.value).then(response => {
    moldingList.value = response.rows
    total.value = response.total
    loading.value = false
  })
}

// 取消按钮
function cancel() {
  open.value = false
  reset()
}

// 表单重置
function reset() {
  form.value = {
    id: null,
    pid: null,
    ptype: null,
    partNumber: null,
    partName: null,
    material: null,
    unitDosage: null,
    unitPrice: null,
    netWeight: null,
    materialHeadWeight: null,
    inferiorMaterial: null,
    wasteMaterialPrice: null,
    cavitiesNumber: null,
    materialWastageRate: null,
    materialDefectRate: null,
    materialOtherExpenses: null,
    materialManagementRate: null,
    materialProfitRate: null,
    injectionMoldingOther: null,
    materialConsumer: null,
    headLossRate: null,
    auxiliaryCost: null,
    materialDefectFee: null,
    materialCost: null,
    materialManagementFee: null,
    materialProfit: null,
    materialTotalCost: null,
    machineModel: null,
    moldType: null,
    costRate: null,
    period: null,
    periodUnit: null,
    efficiency: null,
    moldFixDays: null,
    moldFixCost: null,
    moldFixOtherCost: null,
    moldDefectRate: null,
    moldInjectionOtherCost: null,
    moldInjectionManagementRate: null,
    moldInjectionProfitRate: null,
    moldFixCostPcs: null,
    moldDefectCost: null,
    moldInjectionCost: null,
    moldInjectionManagementCost: null,
    moldProfit: null,
    moldTotalCost: null,
    workstation: null,
    injectionEngineerCount: null,
    injectionEngineerRate: null,
    laborHours: null,
    laborCost: null,
    totalCost: null,
    capacityKpcsPerDay: null,
    UID: null,
    UpdateDate: null,
    CreateDate: null,
    DeleteDate: null
  }
  proxy.resetForm("moldingRef")
}

/** 搜索按钮操作 */
function handleQuery() {
  queryParams.value.pageNum = 1
  getList()
}

/** 重置按钮操作 */
function resetQuery() {
  proxy.resetForm("queryRef")
  handleQuery()
}

// 多选框选中数据
function handleSelectionChange(selection) {
  ids.value = selection.map(item => item.id)
  single.value = selection.length != 1
  multiple.value = !selection.length
}

/** 新增按钮操作 */
function handleAdd() {
  reset()
  open.value = true
  title.value = "添加注塑件成本"
}

/** 修改按钮操作 */
function handleUpdate(row) {
  reset()
  const _id = row.id || ids.value
  getMolding(_id).then(response => {
    form.value = response.data
    open.value = true
    title.value = "修改注塑件成本"
  })
}

/** 提交按钮 */
function submitForm() {
  proxy.$refs["moldingRef"].validate(valid => {
    if (valid) {
      if (form.value.id != null) {
        updateMolding(form.value).then(response => {
          proxy.$modal.msgSuccess("修改成功")
          open.value = false
          getList()
        })
      } else {
        addMolding(form.value).then(response => {
          proxy.$modal.msgSuccess("新增成功")
          open.value = false
          getList()
        })
      }
    }
  })
}

/** 删除按钮操作 */
function handleDelete(row) {
  const _ids = row.id || ids.value
  proxy.$modal.confirm('是否确认删除注塑件成本编号为"' + _ids + '"的数据项？').then(function() {
    return delMolding(_ids)
  }).then(() => {
    getList()
    proxy.$modal.msgSuccess("删除成功")
  }).catch(() => {})
}

/** 导出按钮操作 */
function handleExport() {
  proxy.download('system/molding/export', {
    ...queryParams.value
  }, `molding_${new Date().getTime()}.xlsx`)
}

getList()
</script>
<style scoped>
.calculate{
  margin-top: 30px;
  font-size: 14px;
}
.calculate .el-row {
  height: 55px;
}
.dialog-content{
  padding:50px
}
</style>